package com.hula.onion.book.server.spider.platforms.guangzhouedai;

import com.hula.onion.book.server.common.CommonResponse;
import com.hula.onion.book.server.common.SpiderCommon;
import com.hula.onion.book.server.config.ResponseStatusEnum;
import com.hula.onion.book.server.utils.HttpUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by work on 2018/3/13.
 */
@Component("guangZhouEDaiSpider")
public class GuangZhouEDaiSpider extends SpiderCommon{

    private static final String LOGIN_PAGE_URL="https://www.gzdai.com/user/login.jspx";

    private static final String LOGIN_URL="https://www.gzdai.com/user/userLogin.jspx";


    @Autowired
    private GuangZhouEDaiSpiderHelper spiderHelper;

    @Override
    public CommonResponse execute() {
        //.先请求登陆页面获取token
        String loginHtml=HttpUtils.get(LOGIN_PAGE_URL,getHttpContext());
        if(StringUtils.isEmpty(loginHtml)){
            return new CommonResponse(ResponseStatusEnum.FAIL);
        }
        String loginStr= HttpUtils.post(LOGIN_URL,
                spiderHelper.installRequestParams(loginForm,loginHtml),
                getHttpContext());
        System.out.println(loginStr);
        return null;
    }
}
